﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KylinORM.Utils;
using KylinORM.Data;

namespace KylinORM.CQRS.Publisher
{
    /// <summary>
    /// 为实体更新事件之前提供数据
    /// </summary>
    public class BeforeSubmitEvent : SyncMessage
    {
        /// <summary>
        /// 创建 BeforeOperateEvent 的实例
        /// </summary>
        /// <param name="messageName">操作的类型</param>
        /// <param name="query">更新操作的原始请求</param>
        /// <param name="keys">主键/主键值</param>
        /// <param name="values">非主键/非主键值</param>
        internal BeforeSubmitEvent(string messageName, DataQuery query, ReadonlyOrderedDictionary keys, ReadonlyOrderedDictionary values)
        {
            this.MessageName = messageName;
            this.Query = query;
            this.PrimaryFields = keys ?? new ReadonlyOrderedDictionary(new List<KeyValuePair<string, object>>());
            this.EntityFields = values ?? new ReadonlyOrderedDictionary(new List<KeyValuePair<string, object>>());
        }

        /// <summary>
        /// 获取操作的原始请求
        /// </summary>
        public DataQuery Query
        {
            get;
            private set;
        }
        /// <summary>
        /// 获取操作实体的主键字段
        /// </summary>
        public ReadonlyOrderedDictionary PrimaryFields
        {
            get;
            private set;
        }
        /// <summary>
        /// 获取操作实体的全部字段
        /// </summary>
        public ReadonlyOrderedDictionary EntityFields
        {
            get;
            private set;
        }
    }
}
